package com.mrdeer.merchant.controller;

import com.mrdeer.merchant.api.AppService;
import com.mrdeer.merchant.api.dto.AppDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商户平台-应用管理
 *
 * @author ：xie jianchu
 * @date ：Created in 2020/9/14 0014 9:06
 */
@RestController
@Api(value = "商户平台-应用管理", tags = "商户平台-应用相关")
public class AppController {

    @Reference
    private AppService appService;

    @ApiOperation(value = "商户创建应用")
    @PostMapping(value = "/my/apps")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "app", value = "应用信息", required = true, dataType = "AppDTO", paramType = "body")
    })
    public AppDTO createApp(@RequestBody AppDTO appDTO) {
        //TODO:从Token解析出merchantId
        Long merchantId = 1293415867504066562L;
        return appService.createApp(merchantId, appDTO);
    }

    @ApiOperation("查询商户下的应用列表")
    @GetMapping(value = "/my/apps")
    public List<AppDTO> queryMyApps() {
        Long merchantId = 1293415867504066562L;
        return appService.queryAppByMerchantId(merchantId);
    }

    @ApiOperation("根据应用id查询应用信息")
    @ApiImplicitParam(value = "应用ID", name = "appId", dataType = "String", paramType = "path")
    @GetMapping(value = "/my/apps/{appId}")
    public AppDTO getAppByAppId(@PathVariable String appId) {
        return appService.getAppByAppId(appId);
    }
}
